// pages/manghe/cj/cj.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    num: 1
  },
  random() {
    var _ = this;
    var num = _.data.num;
    if (num == 1) {
      _.setData({
        num: 2
      })
    } else if (num == 2) {
      _.setData({
        num: 3
      })
    } else if (num == 3) {
      _.setData({
        num: 4
      })
    } else {
      _.setData({
        num: 1
      })
    }
    console.log(_.data.num)

  },
  tip() {
    var that = this;
    that.setData({
      fixed: 1
    })
  },
  close() {
    var that = this;
    that.setData({
      fixed: !1
    })
  },

  lottery() {
    var that = this;
    var phone = wx.getStorageSync('mhphone')
    var fx = wx.getStorageSync('fx')
    if (fx.length > 1) {
      wx.request({ //发送请求
        url: 'https://zg99.offcn.com/index/choujiang/getcjusers?actid=42454&callback=?', //接收url
        data: {
          phone: 15355556666,
          limits: 100
        }, //接收参数
        success(res) {
          var jsonStr = res.data;
          jsonStr = jsonStr.replace("(", "");
          jsonStr = jsonStr.replace(")", "");
          if (typeof jsonStr != 'object') {
            jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
            var theJson = JSON.parse(jsonStr);
          }
          console.log(theJson)
          if (theJson.status === 2) {
            wx.request({ //发送请求
              url: 'https://zg99.offcn.com/index/choujiang/lottery?actid=42454&callback=?&sstimes=' + Date.parse(new Date()) / 1000, //接收url
              data: {
                phone: phone
              }, //接收参数
              success(res) {
                var jsonStr = res.data;
                jsonStr = jsonStr.replace("(", "");
                jsonStr = jsonStr.replace(")", "");
                if (typeof jsonStr != 'object') {
                  jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                  var theJson = JSON.parse(jsonStr);
                }
                console.log(theJson)
                wx.setStorageSync('manghe', theJson.prizename)
                wx.setStorageSync('mangheid', theJson.prizeid)
                wx.navigateTo({
                  url: '../result/result',
                })

              }
            })

          } else if (theJson.status === 1) {
            wx.showModal({
              title: '您已经抽过奖了',
              content: '您获得了' + theJson.lists[0].prizename,
              showCancel: false, //去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  that.setData({
                    isRunning: false
                  })
                }

                wx.navigateTo({
                  url: '../result/result',
                })
              }
            })
          } else {
            wx.showModal({
              title: '次数不足',
              content: '您已经进行过抽奖了！',
              showCancel: false, //去掉取消按钮
              success: function (res) {
                if (res.confirm) {
                  that.setData({
                    isRunning: false
                  })
                }
                wx.navigateTo({
                  url: '../result/result',
                })
              }
            })
          }
        }
      })
    } else {
      wx.showToast({
        title: '请先在页面下方获取次数！',
        icon: 'none'
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    console.log(options);
    that.setData({
      area: options.area,
      geneal: options.agent
    })
    if (options.page) {
      that.setData({
        page: options.page
      })
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (res) {
    var that = this;
    if (res.from === 'button') {
      console.log(res.target)
    }
    var fx = wx.getStorageSync('fx')
    wx.setStorageSync('fx', fx + 1)
    if (fx == '1') {
      that.setData({
        shuzi: 1
      })
    }
    return {
      title: "锋‘盲’毕露-中秋国庆盲盒抽取",
      path: 'pages/manghe/index/index?area=' + that.data.area + '&agent=' + that.data.geneal + '&page=' + that.data.page,
      success: function (res) {
        console.log('成功', res)
      }
    }
  },
})